//
//  PayCompanyChooseController.m
//  HuLaQuan
//
//  Created by liyan on 16/1/22.
//  Copyright © 2016年 yuwubao. All rights reserved.
//

#import "PayCompanyChooseController.h"
#import "PlistSearch.h"
#import "ShowCityCell.h"

#import "GenericConvenientPayHomeController.h"
@interface PayCompanyChooseController ()

@property (nonatomic,strong) NSArray *companyList;

@property (nonatomic, copy) NSString *listFileName;
@end

@implementation PayCompanyChooseController
- (void)setType:(CPPayType)type
{
    _type = type;
    switch (_type) {
        case PayElec:
            self.listFileName = @"ElectricityCompanies";
            break;
        case PayGas:
            self.listFileName = @"GasCompanies";
            break;
        case PayWater:
            self.listFileName = @"WaterCompanies";
            break;
        case PayTrafic:
            self.listFileName = @"TraficFineCompanies";
            break;
        default:
            break;
    }
}
- (NSArray *)companyList
{
    if (!_companyList) {
        
        _companyList= [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:self.listFileName ofType:@"plist"]];
        
    }
    return _companyList;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}
-(void)setupUI
{
    self.title = @"选择缴费单位";
    [self setupNavBackButton];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"PlistSearch" bundle:nil] forCellReuseIdentifier:@"searchCompany"];
     [self.tableView registerNib:[UINib nibWithNibName:@"ShowCityCell" bundle:nil] forCellReuseIdentifier:@"show"];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
}
#pragma mark - Delagate
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (0 ==section) {
        return 1;
    }
    else
    {
        return self.companyList.count;
    }
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (0 == indexPath.section) {
        PlistSearch *cell = [tableView dequeueReusableCellWithIdentifier:@"searchCompany"];
        return cell;
    }
    else
    {
        ShowCityCell *cell = [tableView dequeueReusableCellWithIdentifier:@"show"];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.backgroundColor = [UIColor whiteColor];
        cell.titleLabel.text = self.companyList[indexPath.row];
        return cell;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (1 == indexPath.section) {
        

        if ([self.navigationController.viewControllers[1] isKindOfClass:[GenericConvenientPayHomeController class]]) {
            
            GenericConvenientPayHomeController *controller = (GenericConvenientPayHomeController *)self.navigationController.viewControllers[1];
            controller.companyInfo = [@{@"title":self.companyList[indexPath.row]} mutableCopy];
            [controller.tableView reloadData];
            [self.navigationController popToViewController:controller animated:YES];
        }
     
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return kNormalCellHeight;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
